package com.tonicgb.service;

import com.tonicgb.api.front.request.RegisterThirdUserRequest;
import com.tonicgb.mapper.UserMapper;
import com.tonicgb.model.User;
import com.tonicgb.shared.core.crud.service.CrudService;
import com.tonicgb.shared.util.DateUtil;
import com.tonicgb.shared.util.ObjectUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

/**
 * @author zhaiyujin
 * @date 2021-10-05 09:44:36
 * @说明 用户信息管理
 */
@Service
public class UserService extends CrudService<UserMapper, User> {

    /**
     * 通过微信信息注册用户
     * @param thirdUserRequest RegisterThirdUser 三方用户登录注册信息
     * @return User
     */
    public User registerByThird(RegisterThirdUserRequest thirdUserRequest, String type) {
        User user = new User();
        user.setAccount(DigestUtils.md5Hex(ObjectUtil.getUuid() + DateUtil.getNowTime()));
        user.setUserType(type);
        user.setNickname(thirdUserRequest.getNickName());
        user.setAvatar(thirdUserRequest.getAvatar());
        user.setSex(Integer.parseInt(thirdUserRequest.getSex()));
        user.setAddress(thirdUserRequest.getCountry() + "," + thirdUserRequest.getProvince() + "," + thirdUserRequest.getCity());
        save(user);
        return user;
    }




}
